<?
include('../scaffold/tag.php');
include('../controller/handler.php');
include('../controller/philomousia.php');

include('../module/var.inc.php');

session_start();

$hd = new Handler();
$ph = new Philomousia();
$hd->openDB();
$base_url = $hd->getBaseURL();
$tags = $ph->loadTags($hd);
$total = count($tags);

if($_POST!=NULL && $hd->getPassword()==sha1($_SESSION['password'])) {
	$ph->insertContent($_POST['title'], $_POST['author'], $_POST['body'], $_POST['tag'], $_POST['type'], $hd);
	$feedback = "Articolo <span class=\"italic\">".stripslashes($_POST['title'])."</span> aggiunto con successo nella sezione ".
		"<a href=\"".$base_url.$links[$_POST['type']]."\">".$section[$_POST['type']]."</a>.";
}
$hd->closeDB();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="it" lang="it">
<head>
	<? include('../module/head.inc.php'); ?>
	<meta name="robots" content="noindex, nofollow"/>
	<script src="<?echo $base_url;?>js/editor.js" type="text/javascript" charset="utf-8"></script>
</head>

<body>
<div id="content">
<?include('../module/header.inc.php');?>

<?if($hd->getPassword()==sha1($_SESSION['password'])) {?>

<div id="panel_form" class="form">
	<div class="upper_bar_main"><div class="upper_bar_round"></div></div>
	<div class="body_main_left">
	<div class="body_main_right">
	<div class="body_main">
	<form action="article" method="post" accept-charset="utf-8" onsubmit="return articleForm(this);;">
		<h2>Aggiungi articolo</h2>
		<table border="0" cellspacing="0" cellpadding="0">
			<tr>
				<td width="380px">
					<input type="text" class="text" name="title" value=""<?if($total==0){?> disabled<?}?> /> Titolo<br />
					<input type="text" class="text" name="author" value=""<?if($total==0){?> disabled<?}?> /> Autore<br />
				</td><td></td></tr>
				<tr>
				<td><textarea class="content" id="txt" name="body" rows="24" cols="45"<?if($total==0){?> disabled<?}?>></textarea></td>
				<td width="380px">
					<?include("../module/editor.inc.php");?>
					<div id="tag_box"<?if($total==0){?>class="warning"<?}?>>
					<?
					if($total==0) {?>
					<p>Nessun argomento presente in &Phi;lomousia. Per inserirne di nuovi andare in 
					<a href="<?echo $base_url;?>panel/tag">Gestisci argomenti.</a></p>
					<input type="hidden" name="no_tags" value="true" />
					<?} else {
					?>
					<input type="hidden" name="no_tags" value="false" />
					<table id="tag_table" border="0" cellspacing="2" cellpadding="0">
						<tr>
						<?
						$i = 0;
						foreach($tags as $tag) {
							$i++;
						?><td><input type="checkbox" name="tag[<?echo $tag->getId();?>]" value="<?echo $tag->getId();?>" /> 
						<?echo $tag->getName();?></td>
						<?
							if($i%2==0 && $total>$i) echo "</tr><tr>";
						}
						?>
						</tr>
					</table>
					<?}?>
					</div>
					Archivia in: 
					<select class="text" style="width:auto" name="type" >
						<option value="0" selected><?echo $section[0];?></option>
						<option value="1"><?echo $section[1];?></option>
						<option value="2"><?echo $section[2];?></option>
					</select>
				</td>
			</tr>
		</table>
		<p>
		<input type="button" value="Anteprima &rarr;" onclick="showPreview('txt', '<?echo $base_url?>')"<?if($total==0){?> disabled<?}?> />
		<input type="submit" value="Aggiungi &rarr;"<?if($total==0){?> disabled<?}?> /></p>
	</form>
	<?if($feedback) {?><p id="feedback" class="highline"><?echo $feedback;?></p> <?}?>
	<p class="small admin_action">
		<a href="<?echo $base_url;?>panel">&larr; Pannello di amministrazione</a> |
		<a href="<?echo $base_url;?>panel/tag">Gestisci argomenti</a>
	</p>
	</div></div></div>
	<div class="lower_bar_main"><div class="lower_bar_round"></div></div>
</div>

<?include('../module/preview.inc.php');?>
<?include('../module/uploaded.img.inc.php');?>

<?}?>

<? include('../module/footer.inc.php'); ?>
</div>
</body>
</html>
